import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    redirect: "/login",
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  }, {
    path: '/home',
    name: 'home',
    component: () => import('../views/home.vue'),
    redirect:"/xue",
    children:[
      {
        path: '/xue',
        name: 'xue',
        component: () => import('../views/xue.vue')
      },  {
        path: '/shang',
        name: 'shang',
        component: () => import('../views/shang.vue')
      },  {
        path: '/ding',
        name: 'ding',
        component: () => import('../views/ding.vue')
      },  {
        path: '/zhi',
        name: 'zhi',
        component: () => import('../views/zhi.vue')
      }
    ]
  }
]
const router = new VueRouter({
  routes,
});
router.beforeEach((to, from, next) => {
  if (localStorage.getItem("token")) {
      next();
  } else {
      if (to.path == "/login") {
          next();
      } else {
          next("/login");
      }
  }
});
export default router